package com.phychips.utility;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;

import android.os.Environment;

public class Logger 
{
	FileOutputStream m_fos = null;
	public void initFile(String path, String filename) 
	{	
		releaseFile();
		File p = new File(Environment.getExternalStorageDirectory()
				+ "/" + path + "/");

		if (!p.exists()) 
		{
			p.mkdirs();
			// Log.i("logfile", "make dir:" + path.getAbsolutePath());
		}
		try
		{
			File file = new File(p, filename);
			m_fos = new FileOutputStream(file);	    
		} 
		catch (IOException e) 
		{	    
			e.printStackTrace();
		}

	}
	public void write(String s)
	{
		try
		{
			//if(capture_count > 1000)
			if(m_fos != null)
				m_fos.write(s.getBytes());
		}
		catch (IOException e)
		{
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
	public void releaseFile() 
	{
		if (m_fos != null) 
		{
			try
			{
				m_fos.flush();
				m_fos.close();
			}
			catch (IOException e) 
			{
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
			m_fos = null;
		}
	}
	
	

}
